package day4;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
//通过反射使用有参构造
public class TestReflect {
    public static void main(String[] args) {
        //1.获取类对象
        reflectDemo d= null;
        try {
            Class c=Class.forName("day4.reflectDemo");
            Constructor con=c.getDeclaredConstructor(String.class,int.class);
            con.setAccessible(true);
            d = (reflectDemo)con.newInstance("张三",18);
           String name=c.getName();
            //System.out.println("名字："+);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        System.out.println(d);
    }
}
class reflectDemo{
    private String name;
    private int age;
    private reflectDemo(String name, int age) {
        this.name = name;
        this.age = age;
    }
}